<!DOCTYPE html>
<html>
<head>
<!-- This sample demonstrates calling createOffer to get a SDP blob that
     indicates the capabilities of the PeerConnection. -->
<title>Show createOffer Output Demo</title>
<script src="../../base/adapter.js"></script>
<style>
button {
  font: 18px sans-serif;
  padding: 8px;
}
textarea {
  font-family: monospace;
  margin: 2px;
  width:480px;
  height:640px;
}
</style>
</head>
<body>
<h1>WebRTC createOffer Test Page</h1>
<p>This page tests the createOffer method for a WebRTC implementation. It
  creates a PeerConnection, and then prints out the SDP generated by
  createOffer, with the number of desired audio MediaStreamTracks and the
  checked createOffer constraints. Currently, only audio tracks can be added,
  as there is no programmatic way to generate video tracks. (Web Audio is
  used to generate the audio tracks.)</p>
<h3>Tracks</h3>
<p>Number of Audio Tracks<input id="num-audio-tracks" value="0"></input></p>
<h3>Constraints:</h3>
<input id="audio" type="checkbox">Offer To Receive Audio</input><br>
<input id="video" type="checkbox">Offer To Receive Video</input><br>
<input id="vad" type="checkbox">Voice Activity Detection</input><br>
<input id="restart" type="checkbox">Ice Restart</input><br>
<button id="start" onclick="createOffer()">Create Offer</button><br>
<br>
<textarea id="output"></textarea>
<script>
var numAudioTracks = document.getElementById('num-audio-tracks');
var audio = document.getElementById('audio');
var video = document.getElementById('video');
var vad = document.getElementById('vad');
var restart = document.getElementById('restart');
var output = document.getElementById('output');
var pc = new RTCPeerConnection(null);
var wacx = new webkitAudioContext();

function createOffer() {
  var numRequestedAudioTracks = numAudioTracks.value;
  while (numRequestedAudioTracks < pc.getLocalStreams().length) {
    pc.removeStream(pc.getLocalStreams()[pc.getLocalStreams().length - 1]);
  }
  while (numRequestedAudioTracks > pc.getLocalStreams().length) {
    // Create some dummy audio streams using Web Audio.
    // Note that this fails if you try to do more than one track in Chrome
    // right now.
    var dst = wacx.createMediaStreamDestination();
    pc.addStream(dst.stream);
  }
  var offerConstraints = {
    "optional": [
      { "OfferToReceiveAudio": audio.checked },
      { "OfferToReceiveVideo": video.checked },
    ]
  };
  // These constraints confuse Firefox, even if declared as optional.
  if (webrtcDetectedBrowser != "Firefox") {
    offerConstraints.optional.push(
        { "VoiceActivityDetection": vad.checked });
    offerConstraints.optional.push(
        { "IceRestart": restart.checked });
  }
  pc.createOffer(gotDescription, null, offerConstraints);
}

function gotDescription(desc) {
  pc.setLocalDescription(desc);
  output.value = desc.sdp;
}
</script>
</body>
</html>


